import Mock from 'mockjs';
import moment from 'moment';
// 存储用户信息
const state = {
    // 用户信息
    // user:{
    //     id:null,
    //     name:null,
    //     nickname:null,
    //     password:null,

    // },
    user: null,
    //登录记录
    // login_log:{
    //     time:null,
    //     ip:null,
    //     token:null,

    // }
    login_log: null

}
const getters = {
    isLogin(state) {
        return !(!state.login_log || !state.user)
    }
}
const mutations = {
    login(state, customer) {
        state.user = customer.user
        state.login_log = customer.login_log
    }
}
const actions = {
    login(context, user) {
        // console.log('登录')
        const login_log = {
            time: moment().format('yyyy-MM-DD HH:mm:ss'),
            ip: Mock.mock('@ip()'),
            token: Mock.mock('@word(32)')
        }
        context.commit('login', { user, login_log })
    }
}
export default {
    namespaced: true,
    state,
    getters,
    mutations,
    actions
}